package hunterxhunter.greedisland.data;

import hunterxhunter.greedisland.data.enums.AquisitionLevel;
import java.awt.Color;
import java.awt.Rectangle;
import framework.eea.gui.Graphics;

/**
 *
 * @author Markus Schr&ouml;der
 */
public class Card {

    private int number;
    private String name; 
    private AquisitionLevel aquisitionLevel;
    private int quantity;
    
    private String imageRef;
    
    private String text;

    public Card(int number, String name, AquisitionLevel aquilevel, int quantity, String imageRef, String text) {
        this.number = number;
        this.name = name;
        this.aquisitionLevel = aquilevel;
        this.quantity = quantity;
        this.imageRef = imageRef;
        this.text = text;
    }
    
    public Card(int number, String name, AquisitionLevel aquilevel, int quantity, String text) {
        this(number, name, aquilevel, quantity, String.format("/greedisland/img/card/%04d.jpg", number), text);
    }
    
    public void render(int cardX, int cardY, Graphics g) {
    
        g.drawImage("/greedisland/img/card.png", cardX, cardY);

        int firstRowY = 275;
        
        
        g.setColor(Color.black);
        
        //Number
        g.drawString(String.format("%4d", number), 325, firstRowY);
        
        //Name
        String[] namelines = name.split("\n");
        int nameY = firstRowY-2;
        if(namelines.length == 1) {
            g.drawStringHoriCenter(name, 405, firstRowY, 10);
        } else {
            nameY -= 5;
            for(String nameline : namelines) {
                g.drawStringHoriCenter(nameline, 405, nameY, 9);
                nameY += 10;
            }
        }
        
        //Aqui-Quantity
        g.drawString(aquisitionLevel+"-"+ (quantity > -1 ? quantity : "\u221e"), 450, firstRowY);

        //Image
        g.drawImage(imageRef, new Rectangle(cardX + 10, cardY + 40, 170, 102));
        
        
        //TODO bounding box text draw
        /*
        //explain
        String[] lines = text.split("\n");

        int curY = 405;
        for(String line : lines) {
            g.drawStringHoriCenter(line, 405, curY, 8);
            curY += 13;
        }*/
    }
    
    
    @Override
    public String toString() {
        return "| " + number + " | " + name + " | " + aquisitionLevel + "-" + quantity + " |\n" +
               "| [" + imageRef + "] |\n" +
               "| " + text.substring(0, 15) + "... |";
    }
    
    /**
     * @return the number
     */
    public int getNumber() {
        return number;
    }

    /**
     * @param number the number to set
     */
    public void setNumber(int number) {
        this.number = number;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the aquisitionLevel
     */
    public AquisitionLevel getAquisitionLevel() {
        return aquisitionLevel;
    }

    /**
     * @param aquisitionLevel the aquisitionLevel to set
     */
    public void setAquisitionLevel(AquisitionLevel aquisitionLevel) {
        this.aquisitionLevel = aquisitionLevel;
    }

    /**
     * @return the quantity
     */
    public int getQuantity() {
        return quantity;
    }

    /**
     * @param quantity the quantity to set
     */
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    /**
     * @return the imageRef
     */
    public String getImageRef() {
        return imageRef;
    }

    /**
     * @param imageRef the imageRef to set
     */
    public void setImageRef(String imageRef) {
        this.imageRef = imageRef;
    }

    /**
     * @return the text
     */
    public String getText() {
        return text;
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = text;
    }
    
}
